﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace Looptribe.Moodlin8.Model
{
    [DebuggerDisplay("{Id} [{Name}]")]
    public class Assignment
    {
        public long Id { get; set; }
        public long Course { get; set; }

        public string Name { get; set; }

        public bool NoSubmissions { get; set; }
        public bool SubmissionDrafts { get; set; }
        public bool SendNotifications { get; set; }
        public bool SendLateNotifications { get; set; }

        public DateTime? DueDate { get; set; }
        public DateTime? AllowSubmissionsFromDate { get; set; }

        public int Grade { get; set; }

        public DateTime? TimeModified { get; set; }

        public bool CompletionSubmit { get; set; }

        public DateTime? CutoffDate { get; set; }

        public bool TeamSubmission { get; set; }
        public bool RequireAllTeamMembersSubmit { get; set; }
        public int TeamSubmissionGroupingId { get; set; }
        public bool BlindMarking { get; set; }
        public bool RevealIdentities { get; set; }
        public bool RequireSubmissionStatement { get; set; }

        public string Intro { get; set; }
        public int IntroFormat { get; set; }

        public List<Config> Configs { get; set; }

        public GradeExternal Grades { get; set; }

        public bool IsCorrected
        {
            get
            {
                return Grades.Items.Count > 0 &&
                      (Grades.Items.First().Grades.Any(a => a.DateSubmitted.HasValue) ||
                      Grades.Items.First().Grades.Any(a => a.DateGraded.HasValue));
            }
        }

        [DebuggerDisplay("{Id} - {Plugin} - {Subtype} - {Name}")]
        public class Config
        {
            public long Id { get; set; }
            public string Plugin { get; set; }
            public string Subtype { get; set; }
            public string Name { get; set; }
            public string Value { get; set; }
        }

        public class GradeExternal
        {
            public List<GradeItem> Items { get; set; }
        }
    }
}
